
const { query } = require('../db/search_mysql')

class Hotword {
  constructor () {
    this.tableName = 'hot_words'
  }

  getList (options = { app: 'zituwang', page: 1, page_size: 20, status: 1 }) {
    let sql = `SELECT words AS keyword, is_new, is_hot
              FROM ${this.tableName} WHERE id 
              AND app = ?
              AND status = ?
              `

    sql += ` GROUP BY words `
    sql += ` ORDER BY sort DESC, id DESC`
    sql += ` limit ${(options.page - 1) * options.page_size},${options.page_size};`

    return query(sql, [options.app, options.status])
  }
}

module.exports = new Hotword()
